package HomeWork;

import Domain.Student;

/*
定义一个数组来存储5个学生对象,学生类:属性:name,score,
给这5个学生对象赋值,然后将成绩大于等于80分的学员成绩存入新数组中,并计算输出学生的平均成绩。
 */
public class Code4 {
    public static void main(String[] args) {
        Student[] students = new Student[5];
        Student[] hege = new Student[5];//记录合格人员

        Student stu1 = new Student("张三",90.0);
        Student stu2 = new Student("赵四",20.0);
        Student stu3 = new Student("王五",80.0);
        Student stu4 = new Student("李六",30.0);
        Student stu5 = new Student("吴七",60.0);

        students[0] = stu1;
        students[1] = stu2;
        students[2] = stu3;
        students[3] = stu4;
        students[4] = stu5;


        int index = 0;
        double sum = 0;
        for (int i = 0; i < students.length; i++) {
            sum += students[i].getScore();
            if (students[i].getScore() >= 80.0) {
                hege[index] = students[i];
                index++;
            }
        }
        //输出合格人员姓名与成绩
        System.out.println("合格人员有：");
           for (int i = 0; i < index; i++) {
               System.out.println("姓名：" + hege[i].getName() + "\t" + "成绩：" + hege[i].getScore());
           }

           //输出平均成绩
        System.out.println("平均成绩为：" + sum / students.length);

    }


}

